/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package SwingForms;

import LogicaClasesNew.LineaOrden;
import LogicaClasesNew.OrdenCompra;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import LogicaClasesNew.ControladorOrdenCompra;

/**
 *
 * @author Roxio
 */
public class frmInfoOrdenCompra extends javax.swing.JInternalFrame {

    /**
     * Creates new form frmInfoOrdenCompraNueva
     */
    public frmInfoOrdenCompra() {
        initComponents();
        CrearModeloJT_OrdenCompraClientes();
        CrearModeloJT_InfoOrdenOrdenes();
        llenartablaJT_InfoOrden();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        JB_InfoOrdenCompraCerrar = new javax.swing.JButton();
        JL_InfoUsuarioNickName = new javax.swing.JLabel();
        JTF_InfoOrdenNickname = new javax.swing.JTextField();
        JL_UsuarioMail = new javax.swing.JLabel();
        JTF_InfoOrdenEmail = new javax.swing.JTextField();
        JL_InfoOrdenNumero = new javax.swing.JLabel();
        JTF_InfoOrdenNumero = new javax.swing.JTextField();
        JL_InfoOrdenNumero1 = new javax.swing.JLabel();
        JTF_InfoOrdenFecha = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        JT_InfoOrden = new javax.swing.JTable();
        JL_UsuarioMail1 = new javax.swing.JLabel();
        JTF_InfoOrdenTotal = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        JT_InfoOrdenOrdenes = new javax.swing.JTable();

        jLabel2.setFont(new java.awt.Font("Trebuchet MS", 1, 14)); // NOI18N
        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/InfoOrdCompragreen.png"))); // NOI18N

        JB_InfoOrdenCompraCerrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Cerrar.png"))); // NOI18N
        JB_InfoOrdenCompraCerrar.setToolTipText("Cierra Ventana");
        JB_InfoOrdenCompraCerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_InfoOrdenCompraCerrarActionPerformed(evt);
            }
        });

        JL_InfoUsuarioNickName.setText("NickName:");

        JTF_InfoOrdenNickname.setEditable(false);
        JTF_InfoOrdenNickname.setForeground(new java.awt.Color(153, 0, 153));
        JTF_InfoOrdenNickname.setToolTipText("Ingrese un Alias que lo Identificar{a");
        JTF_InfoOrdenNickname.setCaretColor(new java.awt.Color(153, 0, 153));
        JTF_InfoOrdenNickname.setDisabledTextColor(new java.awt.Color(153, 0, 153));

        JL_UsuarioMail.setText("Correo  electronico:");

        JTF_InfoOrdenEmail.setEditable(false);
        JTF_InfoOrdenEmail.setForeground(new java.awt.Color(153, 0, 153));
        JTF_InfoOrdenEmail.setDisabledTextColor(new java.awt.Color(153, 0, 153));

        JL_InfoOrdenNumero.setText("Numero:");

        JTF_InfoOrdenNumero.setEditable(false);
        JTF_InfoOrdenNumero.setForeground(new java.awt.Color(153, 0, 153));
        JTF_InfoOrdenNumero.setToolTipText("Ingrese un Alias que lo Identificar{a");
        JTF_InfoOrdenNumero.setCaretColor(new java.awt.Color(153, 0, 153));
        JTF_InfoOrdenNumero.setDisabledTextColor(new java.awt.Color(153, 0, 153));

        JL_InfoOrdenNumero1.setText("Fecha");

        JTF_InfoOrdenFecha.setEditable(false);
        JTF_InfoOrdenFecha.setForeground(new java.awt.Color(153, 0, 153));
        JTF_InfoOrdenFecha.setToolTipText("Ingrese un Alias que lo Identificar{a");
        JTF_InfoOrdenFecha.setCaretColor(new java.awt.Color(153, 0, 153));
        JTF_InfoOrdenFecha.setDisabledTextColor(new java.awt.Color(153, 0, 153));

        JT_InfoOrden.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        JT_InfoOrden.setEnabled(false);
        jScrollPane1.setViewportView(JT_InfoOrden);

        JL_UsuarioMail1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        JL_UsuarioMail1.setText("TOTAL:");

        JTF_InfoOrdenTotal.setEditable(false);
        JTF_InfoOrdenTotal.setForeground(new java.awt.Color(153, 0, 153));
        JTF_InfoOrdenTotal.setDisabledTextColor(new java.awt.Color(153, 0, 153));

        jLabel1.setFont(new java.awt.Font("Trebuchet MS", 1, 14)); // NOI18N
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/SeleccioneOrdCompragreen.png"))); // NOI18N

        JT_InfoOrdenOrdenes.setForeground(new java.awt.Color(51, 0, 51));
        JT_InfoOrdenOrdenes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Nickname", "nombre"
            }
        ));
        JT_InfoOrdenOrdenes.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                JT_InfoOrdenOrdenesMouseClicked(evt);
            }
        });
        JT_InfoOrdenOrdenes.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentMoved(java.awt.event.ComponentEvent evt) {
                JT_InfoOrdenOrdenesComponentMoved(evt);
            }
        });
        jScrollPane2.setViewportView(JT_InfoOrdenOrdenes);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(308, 308, 308)
                        .addComponent(JL_UsuarioMail1)
                        .addGap(18, 18, 18)
                        .addComponent(JTF_InfoOrdenTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(123, 123, 123)
                        .addComponent(JB_InfoOrdenCompraCerrar))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(42, 42, 42)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(JL_InfoOrdenNumero1)
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(JL_UsuarioMail, javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(JL_InfoUsuarioNickName)))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(JTF_InfoOrdenNumero, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                .addComponent(JTF_InfoOrdenFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(JTF_InfoOrdenEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE)
                                                .addComponent(JTF_InfoOrdenNickname))))
                                    .addComponent(JL_InfoOrdenNumero))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 54, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 311, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel1))
                                .addGap(24, 24, 24)))))
                .addGap(27, 27, 27))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(9, 9, 9)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(JL_InfoOrdenNumero)
                            .addComponent(JTF_InfoOrdenNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(JTF_InfoOrdenFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(JL_InfoOrdenNumero1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(JL_InfoUsuarioNickName)
                            .addComponent(JTF_InfoOrdenNickname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(JL_UsuarioMail)
                            .addComponent(JTF_InfoOrdenEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(42, 42, 42)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(JB_InfoOrdenCompraCerrar)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(JTF_InfoOrdenTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(JL_UsuarioMail1)))
                .addContainerGap(31, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    public static DefaultTableModel modeloJT_InfoOrden;
     
     private void CrearModeloJT_OrdenCompraClientes(){
         try {
             modeloJT_InfoOrden = (new DefaultTableModel(
                null, new String [] {
                "Numero de Referencia","Producto", "Cantidad", "Precio Unitario"}){
                Class[] types = new Class [] {
                java.lang.String.class,
                java.lang.String.class,
                java.lang.String.class,
                java.lang.String.class
    };
                boolean[] canEdit = new boolean [] {
                false,false
                };
                @Override
                public Class getColumnClass(int columnIndex) {
                   return types [columnIndex];
                }
                @Override
                public boolean isCellEditable(int rowIndex, int colIndex){
                   return canEdit [colIndex];
                }
            });
          JT_InfoOrden.setModel(modeloJT_InfoOrden);
         } catch (Exception e) {
             JOptionPane.showMessageDialog(null,e.toString());
            }    
     }
     public static DefaultTableModel ModeloJT_InfoOrdenOrdenes;
     private void CrearModeloJT_InfoOrdenOrdenes(){
         try {
             ModeloJT_InfoOrdenOrdenes = (new DefaultTableModel(
                null, new String [] {
                "Numero de Orden"}){
                Class[] types = new Class [] {
                java.lang.String.class
    };
                boolean[] canEdit = new boolean [] {
                false,false
                };
                @Override
                public Class getColumnClass(int columnIndex) {
                   return types [columnIndex];
                }
                @Override
                public boolean isCellEditable(int rowIndex, int colIndex){
                   return canEdit [colIndex];
                }
            });
          JT_InfoOrdenOrdenes.setModel(ModeloJT_InfoOrdenOrdenes);
         } catch (Exception e) {
             JOptionPane.showMessageDialog(null,e.toString());
            }    
     }
     
    private void llenartablaJT_InfoOrden(){
    //Clear_JT_InfoOrden();    
    ControladorOrdenCompra jpaOrdenCompra = new ControladorOrdenCompra();   
    try {
            Object A[] = null;
            List<OrdenCompra> ListaOrdenCompra;
            ListaOrdenCompra= jpaOrdenCompra.findOrdenCompraEntities();
            int j2 = 0;
            for (int i = 0; i < ListaOrdenCompra.size(); i++) {
                System.out.print("i vale:"+i);
                if(!ListaOrdenCompra.get(i).isBajaLogica()){
                    System.out.print("j vale:"+j2);
                    ModeloJT_InfoOrdenOrdenes.addRow(A);
                    ModeloJT_InfoOrdenOrdenes.setValueAt(ListaOrdenCompra.get(i).getNumero(), j2, 0);
                    j2+=1;
            }
          }
        }
        catch (Exception e){
            getToolkit().beep();
            JOptionPane.showMessageDialog(this, e.getMessage());
        }
    } 
    private void JB_InfoOrdenCompraCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_InfoOrdenCompraCerrarActionPerformed
        //Oculta formulario
        this.setVisible (false);
        
        
        
    }//GEN-LAST:event_JB_InfoOrdenCompraCerrarActionPerformed

    private void JT_InfoOrdenOrdenesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_JT_InfoOrdenOrdenesMouseClicked
        // TODO add your handling code here:
            int row= JT_InfoOrdenOrdenes.getSelectedRow();
            int numero=Integer.parseInt((JT_InfoOrdenOrdenes.getModel().getValueAt(row, 0).toString()));
            ControladorOrdenCompra jpaOrdenCompra = new ControladorOrdenCompra();
            OrdenCompra miorden= jpaOrdenCompra.findOrdenCompra(numero);
            JTF_InfoOrdenNickname.setText(miorden.getCliente().getNickname());
            JTF_InfoOrdenEmail.setText(miorden.getCliente().getMail());
            JTF_InfoOrdenFecha.setText(miorden.getFechaOrden());
            String minumero=String.valueOf(miorden.getNumero());
            String mitotal=String.valueOf(miorden.getPrecioTotal());
            JTF_InfoOrdenNumero.setText(minumero);
            JTF_InfoOrdenTotal.setText(mitotal);
            //VACIO
            Clear_JT_InfoOrden();
            List<LineaOrden> lineasorden;
            lineasorden= miorden.getLineasOrden();
            try {
            Object A[] = null;
            for (int i = 0; i < lineasorden.size(); i++) {
                //modeloproductos=null;
                modeloJT_InfoOrden.addRow(A);
                modeloJT_InfoOrden.setValueAt(lineasorden.get(i).getP().getNumRef(), i, 0);
                modeloJT_InfoOrden.setValueAt(lineasorden.get(i).getP().getNombre(), i, 1);
                modeloJT_InfoOrden.setValueAt(lineasorden.get(i).getCantidad(), i, 2);
                modeloJT_InfoOrden.setValueAt(lineasorden.get(i).getPrecioactual(), i, 3);
                }
            }
            catch (Exception e)
                {
                JOptionPane.showMessageDialog(this, e.getMessage());
            }
    
    }//GEN-LAST:event_JT_InfoOrdenOrdenesMouseClicked
    private void Clear_JT_InfoOrden(){
    for (int i = 0; i < modeloJT_InfoOrden.getRowCount(); i++) {
    modeloJT_InfoOrden.removeRow(i);
    i-=1;
    }
    }
    private void JT_InfoOrdenOrdenesComponentMoved(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_JT_InfoOrdenOrdenesComponentMoved
        // TODO add your handling code here:
    }//GEN-LAST:event_JT_InfoOrdenOrdenesComponentMoved


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton JB_InfoOrdenCompraCerrar;
    private javax.swing.JLabel JL_InfoOrdenNumero;
    private javax.swing.JLabel JL_InfoOrdenNumero1;
    private javax.swing.JLabel JL_InfoUsuarioNickName;
    private javax.swing.JLabel JL_UsuarioMail;
    private javax.swing.JLabel JL_UsuarioMail1;
    private javax.swing.JTextField JTF_InfoOrdenEmail;
    private javax.swing.JTextField JTF_InfoOrdenFecha;
    private javax.swing.JTextField JTF_InfoOrdenNickname;
    private javax.swing.JTextField JTF_InfoOrdenNumero;
    private javax.swing.JTextField JTF_InfoOrdenTotal;
    private javax.swing.JTable JT_InfoOrden;
    private javax.swing.JTable JT_InfoOrdenOrdenes;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    // End of variables declaration//GEN-END:variables
}
